<template>
  <div>
    <Select v-model="value"
      :multiple='multiple'
      filterable
      :clearable="clearable"
      :max-tag-count='maxTagCount'
      :placeholder="placeholder"
      :disabled='disabled'>
      <Option
        v-for="item in list"
        :disabled='item.disabled'
        :key="item.value"
        :label="item.text"
        :value="item.value.toString()">
      </Option>
    </Select>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  export default {
    props: {
      value: {
        type: [String, Number],
        default: ''
      },
      listType: {
        type: String,
        default: 'brandList'
      },
      placeholder: {
        type: String,
        default: '请选择'
      },
      disabled: {
        type: Boolean,
        default: false
      },
      selfList: {
        type: Array,
        default: ()=> []
      },
      clearable: {
        type: Boolean,
        default: true
      },
      multiple: {
        type: Boolean,
        default: false
      },
      maxTagCount: {
        type: Number,
        default: 2
      }
    },
    data() {
      return {
        currValue: []
      }
    },
    mounted() {
      switch (this.listType) {
        case 'brandList':
          this.$store.dispatch('getBrandList', true)
          break;
        case 'storeTypeList':
          this.$store.dispatch('getStoreTypeList', true)
          break;
        default:
          break;
      }
    },
    computed: {
      /**
       * 品牌 门店类型列表 门店类型列表 仓库启用状态 星标状态 安装协议安装类型 服务协议安装类型 启用状态  经销商列表 季度列表
       * */
      ...mapGetters([
        'brandList','storeTypeData', 'storeTypeList' ,'quarterCheckStatus','fundCheckStatus','wareHouseUseTypeList','starTypeList',
        'enableTypeList', 'dealerList', 'quarterList', 'contractTypeList',
        'isHave', 'integralAuditStatus'
      ]),
      list() {
        return this[this.listType]
      }
    },
    methods: {
      /**
       * 用于切换省份时动态更新经销商列表
       * type 需要获取的列表 定义在/store/list/index
       * params 接口参数
       */
      getListDispath(type, params) {
        this.$store.dispatch(type, params)
      },
    },
    watch: {
      value(value) {
        let item;
        if(this.listType == 'dealerList' && value) {
          item = this.dealerList.find(item => item.id == value.split('&')[1])
        }
        this.$emit('input', value, item)
      }
    }
  }
</script>
